package com.windbell.util;

import java.util.ArrayList;
import java.util.List;

import org.codehaus.jackson.map.ObjectMapper;

public class JsonUtils {
	public static void main(String[] args) {

		String value = " [{\"id\":\"2\",\"name\":\"CNBLOGS新闻区\"},{\"id\":\"1\",\"name\":\"CSDN灌水TOP10\"}] ";
		List list = json2list(value);
	}

	public static <T> T json2obj(String json, Class<T> t) {
		try {
			return new ObjectMapper().readValue(json, t);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public static List json2list(String json) {
		try {
			List list = new ObjectMapper().readValue(json, List.class);
			return list;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new ArrayList();
	}
}
